$(document).ready(function(){
	if ($("#container").length > 0)
    {
		$('#container').masonry({
			itemSelector: '.col',
			singleMode: true
		});
    }
})

$(window).scroll(function(){
	// 当滚动到最底部以上100像素时， 加载新内容
	if ($(document).height() - $(this).scrollTop() - $(this).height() < 100)
	{
		showMoreCaiPu();
	}
});

/**
 * @desc:瀑布流发送AJAX请求数据
**/
function showMoreCaiPu()
{
	var parm = $("#param");
	var offset = parseInt(parm.attr('offset'));
	var cate = parm.attr('cate');
	if (offset < 20)
	{
		$("#param").ajaxStart(function(){
			$(window).unbind('scroll',showMoreCaiPu);
		});
		offset = offset + 20;
		parm.attr('offset', offset);
		$("#showloading").show();
		$.ajax({
			type:"post",
			url:"/?uajax/ajaxgetMoreCaipu",
			data:"offset="+offset+"&cate="+cate,
			dataType:"text",
			async: false,
			success: function(msg)
			{
				var $boxes  = $(msg);
				$(window).scroll(showMoreCaiPu);
				$boxes.hide();
				$('#container').append( $boxes ).masonry('appended', $boxes);
				$boxes.fadeIn(3000);
				$(".pagediv").show();
			}
		})
		$("#showloading").hide();
	}else
	{
		$(window).unbind('scroll',showMoreCaiPu);
	}
}